package com.zeh.interceptor;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 登录拦截器
 */
public class LoginInterceptor extends HandlerInterceptorAdapter{
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws IOException, IOException {
        //判断session里面是否有用户，没有的话重定向到登录页面
        if(request.getSession().getAttribute("user")== null){
            response.sendRedirect("/admin");
            return false;
        }
        return true;
    }

}